/**
 * output package name
 */
package com.kingdee.eas.crm.market.client;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.extendcontrols.KDBizPromptBox;
import com.kingdee.bos.ctrl.kdf.table.BasicView;
import com.kingdee.bos.ctrl.kdf.table.ICell;
import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.ctrl.kdf.table.KDTDefaultCellEditor;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.ctrl.kdf.table.event.KDTEditEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTMouseEvent;
import com.kingdee.bos.ctrl.swing.KDComboBox;
import com.kingdee.bos.ctrl.swing.KDDatePicker;
import com.kingdee.bos.ctrl.swing.KDTextField;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.framework.DynamicObjectFactory;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.crm.market.IsFinishEnum;
import com.kingdee.eas.crm.market.MarketPlanEntryFactory;
import com.kingdee.eas.crm.market.MarketPlanEntryInfo;
import com.kingdee.eas.crm.market.MarketPlanEntrySellPlanEntryCollection;
import com.kingdee.eas.crm.market.MarketPlanEntrySellPlanEntryFactory;
import com.kingdee.eas.crm.market.MarketPlanEntrySellPlanEntryInfo;
import com.kingdee.eas.crm.market.MarketSchemeEntryCollection;
import com.kingdee.eas.crm.market.MarketSchemeEntryFactory;
import com.kingdee.eas.crm.market.MarketSchemeEntryInfo;
import com.kingdee.eas.crm.market.MarketSchemeFactory;
import com.kingdee.eas.crm.market.MarketSchemeInfo;
import com.kingdee.eas.fdc.basecrm.client.CRMClientHelper;
import com.kingdee.eas.fdc.basedata.CurProjectCollection;
import com.kingdee.eas.fdc.basedata.CurProjectFactory;
import com.kingdee.eas.fdc.basedata.FDCBillStateEnum;
import com.kingdee.eas.fdc.basedata.FDCCommonServerHelper;
import com.kingdee.eas.fdc.basedata.FDCHelper;
import com.kingdee.eas.fdc.basedata.client.FDCClientHelper;
import com.kingdee.eas.fdc.basedata.client.FDCMsgBox;
import com.kingdee.eas.fdc.basedata.util.KDDetailedArea;
import com.kingdee.eas.fdc.basedata.util.KDDetailedAreaDialog;
import com.kingdee.eas.fdc.contract.ContractBillInfo;
import com.kingdee.eas.fdc.contract.ContractWithoutTextInfo;
import com.kingdee.eas.fdc.market.client.ContractPromptDialog;
import com.kingdee.eas.fdc.market.client.TableUtils;
import com.kingdee.eas.fdc.market.client.VerifyInputUtil;
import com.kingdee.eas.fi.cas.IPaymentBill;
import com.kingdee.eas.fi.cas.PaymentBillCollection;
import com.kingdee.eas.fi.cas.PaymentBillFactory;
import com.kingdee.eas.util.SysUtil;

/**
 * output class name
 */
public class MarketSchemeEditUI extends AbstractMarketSchemeEditUI
{
    private static final Logger logger = CoreUIObject.getLogger(MarketSchemeEditUI.class);
    
    /**
     * output class constructor
     */
    public MarketSchemeEditUI() throws Exception
    {
        super();
    }
	
	protected KDTable getDetailTable()
	{
		return kdtEntry;
	}
	
	public void onLoad()
	    throws Exception
	{
	     initUI();
	     super.onLoad();
	     setPreferredSize(getMaximumSize());
	     menuTable1.setVisible(false);
	     btnAddLine.setVisible(false);
	     btnInsertLine.setVisible(false);
	     btnRemoveLine.setVisible(false);
	     actionCreateFrom.setVisible(false);
	     actionTraceDown.setVisible(false);
	     actionTraceUp.setVisible(false);
	     actionCopy.setVisible(false);
	     actionCopyFrom.setVisible(false);
	     chkMenuItemSubmitAndAddNew.setVisible(false);
	     chkMenuItemSubmitAndAddNew.setSelected(false);
	     chkMenuItemSubmitAndPrint.setVisible(false);
	     chkMenuItemSubmitAndPrint.setSelected(false);
	     menuBiz.setVisible(false);
	     menuSubmitOption.setVisible(false);
	     actionAddNew.setVisible(false);
	     prmtOrgUnit.setEnabled(false);
	     prmtEnterprisePlan.setEnabled(false);
	     prmtSellProject.setEnabled(false);
	     comboState.setEnabled(false);
	     contThemeName.setEnabled(false);
	     contTotalFactAmount.setEnabled(false);
	     contTotalContractAmount.setEnabled(false);
	     contTotalPayAmount.setEnabled(false);
	     txtThemeDescription.setEnabled(false);
	     pkStartDate.setRequired(true);
	     pkEndDate.setRequired(true);
	     CurProjectCollection pro = CurProjectFactory.getRemoteInstance().getCurProjectCollection((new StringBuilder("select * from where fullorgunit.id='")).append(SysContext.getSysContext().getCurrentFIUnit().getId().toString()).append("'").toString());
	     FilterInfo contractFilter = null;
	     if(pro.size() > 0)
	    {
	         contractFilter = new FilterInfo();
	         Set id = new HashSet();
	         for(int i = 0; i < pro.size(); i++)
	             id.add(pro.get(i).getId().toString());
	
	         contractFilter.getFilterItems().add(new FilterItemInfo("contractType.parent.name", "\u8425\u9500\u5408\u540C"));
	         contractFilter.getFilterItems().add(new FilterItemInfo("curProject.id", id, CompareType.INCLUDE));
	         contractFilter.getFilterItems().add(new FilterItemInfo("state", "2SUBMITTED"));
	         contractFilter.getFilterItems().add(new FilterItemInfo("state", "4AUDITTED"));
	         contractFilter.setMaskString("#0 and #1 and (#2 or #3)");
	    }
	     ContractPromptDialog contract = new ContractPromptDialog(this, contractFilter);
	     KDBizPromptBox box = new KDBizPromptBox();
	/* 1*/        KDTDefaultCellEditor f7contractNumber = new KDTDefaultCellEditor(box);
	     box.setDisplayFormat("$number$");
	     box.setEditFormat("$number$");
	     box.setCommitFormat("$number$");
	     box.setSelector(contract);
	     box.setEditable(false);
	     box.setEnabledMultiSelection(false);
	     kdtEntry.getColumn("contractNumber").setEditor(f7contractNumber);
	
	}
	
	public void initUI()
	{
	     kdtEntry.checkParsed();
	     TableUtils.changeTableNumberFormat(kdtEntry, new String[] {
	         "factAmount", "payAmount", "contractAmount"
	    });
	     kdtEntry.getColumn("factAmount").setEditor(TableUtils.getCellNumberEdit());
	     kdtEntry.getColumn("payAmount").setEditor(TableUtils.getCellNumberEdit());
	     kdtEntry.getColumn("contractAmount").setEditor(TableUtils.getCellNumberEdit());
	     KDDatePicker tblMainPlan_startTime_PromptBox = new KDDatePicker();
	     tblMainPlan_startTime_PromptBox.setName("tblMainPlan_endTime_PromptBox");
	     tblMainPlan_startTime_PromptBox.setVisible(true);
	     tblMainPlan_startTime_PromptBox.setEnabled(true);
	     KDTDefaultCellEditor tblMainPlan_startTime_CellEditor = new KDTDefaultCellEditor(tblMainPlan_startTime_PromptBox);
	     kdtEntry.getColumn("startTime").setEditor(tblMainPlan_startTime_CellEditor);
	     KDDatePicker tblMainPlan_endTime_PromptBox = new KDDatePicker();
	     tblMainPlan_endTime_PromptBox.setName("tblMainPlan_endTime_PromptBox");
	     tblMainPlan_endTime_PromptBox.setVisible(true);
	     tblMainPlan_endTime_PromptBox.setEnabled(true);
	     KDTDefaultCellEditor tblMainPlan_endTime_CellEditor = new KDTDefaultCellEditor(tblMainPlan_endTime_PromptBox);
	     kdtEntry.getColumn("endTime").setEditor(tblMainPlan_endTime_CellEditor);
	     KDComboBox comboField = new KDComboBox();
	     for(int i = 0; i < IsFinishEnum.getEnumList().size(); i++)
	         comboField.addItem(IsFinishEnum.getEnumList().get(i));
	
	     KDTDefaultCellEditor comboEditor = new KDTDefaultCellEditor(comboField);
	     kdtEntry.getColumn("isEnd").setEditor(comboEditor);
	     contTotalPlanAmount.setEnabled(false);
	     CRMClientHelper.changeTableNumberFormat(kdtEntry, new String[] {
	         "planAmount", "factAmount", "contractAmount", "payAmount"
	    });
	}
	
	public void loadEntry()
	{
	     SelectorItemCollection sel = new SelectorItemCollection();
	     sel.add("*");
	     sel.add("subject.*");
	     sel.add("classify.*");
	     sel.add("mediaName.*");
	     BigDecimal planAmount = new BigDecimal("0.00");
	     for(int i = 0; i < kdtEntry.getRowCount(); i++)
	    {
	         if(IsFinishEnum.FINISH.equals(kdtEntry.getRow(i).getCell("isEnd").getValue()))
	        {
	             kdtEntry.getRow(i).getCell("startTime").getStyleAttributes().setBackground(FDCClientHelper.KDTABLE_COMMON_BG_COLOR);
	             kdtEntry.getRow(i).getCell("endTime").getStyleAttributes().setBackground(FDCClientHelper.KDTABLE_COMMON_BG_COLOR);
	             kdtEntry.getRow(i).getCell("factAmount").getStyleAttributes().setBackground(FDCClientHelper.KDTABLE_COMMON_BG_COLOR);
	        } else
	        {
	             kdtEntry.getRow(i).getCell("startTime").getStyleAttributes().setBackground(java.awt.Color.WHITE);
	             kdtEntry.getRow(i).getCell("endTime").getStyleAttributes().setBackground(java.awt.Color.WHITE);
	             kdtEntry.getRow(i).getCell("factAmount").getStyleAttributes().setBackground(java.awt.Color.WHITE);
	        }
	         String sellId = (String)kdtEntry.getRow(i).getCell("sellPlanID").getValue();
	         try
	        {
	             MarketPlanEntrySellPlanEntryInfo esp = MarketPlanEntrySellPlanEntryFactory.getRemoteInstance().getMarketPlanEntrySellPlanEntryInfo(new ObjectUuidPK(sellId), sel);
	             kdtEntry.getRow(i).getCell("accountView").setValue(esp.getSubject());
	             kdtEntry.getRow(i).getCell("channelType").setValue(esp.getClassify());
	             kdtEntry.getRow(i).getCell("mediaName").setValue(esp.getMediaName());
	             kdtEntry.getRow(i).getCell("planAmount").setValue(esp.getPlanCost());
	             kdtEntry.getRow(i).getCell("contentItem").setValue(esp.getProceeding());
	             if(esp.getPlanCost() != null)
	                 planAmount = planAmount.add(esp.getPlanCost());
	             BOSUuid id = ((MarketSchemeEntryInfo)kdtEntry.getRow(i).getUserObject()).getContractNumberID();
	             ObjectUuidPK pk = new ObjectUuidPK(id);
	             if(id != null)
	            {
	                 IObjectValue objectValue = DynamicObjectFactory.getRemoteInstance().getValue(pk.getObjectType(), pk);
	                 if(objectValue instanceof ContractBillInfo)
	                     kdtEntry.getRow(i).getCell("contractNumber").setValue((ContractBillInfo)objectValue);
	                 else
	                     kdtEntry.getRow(i).getCell("contractNumber").setValue((ContractWithoutTextInfo)objectValue);
	            }
	        }
	         catch(Exception e)
	        {
	             e.printStackTrace();
	        }
	    }
	
	     txtTotalPlanAmount.setValue(planAmount);
	     if(pkStartDate.getValue() == null && pkEndDate.getValue() == null)
	         try
	        {
	             setHeadTime();
	        }
	         catch(BOSException e)
	        {
	             e.printStackTrace();
	        }
	}
	
	public void loadFields()
	{
	     detachListeners();
	     super.loadFields();
	     setSaveActionStatus();
	     int idx = idList.getCurrentIndex();
	     if(idx >= 0)
	         billIndex = (new StringBuilder("(")).append(idx + 1).append(")").toString();
	     else
	         billIndex = "";
	     refreshUITitle();
	     setAuditButtonStatus(getOprtState());
	     loadEntry();
	     attachListeners();
	}
	
	protected void chkIsEnd_stateChanged(ChangeEvent e)
	    throws Exception
	{
	     super.chkIsEnd_stateChanged(e);
	     if(chkIsEnd.isSelected())
	    {
	         for(int i = 0; i < kdtEntry.getRowCount(); i++)
	             if(IsFinishEnum.UNSTART.equals(kdtEntry.getRow(i).getCell("isEnd").getValue()) || kdtEntry.getRow(i).getCell("isEnd").getValue() == null)
	            {
	                 kdtEntry.getRow(i).getCell("isEnd").setValue(IsFinishEnum.FINISH);
	                 setEndTime(kdtEntry.getRow(i));
	            }
	
	    }
	}
	
	public void setEndTime(IRow row)
	    throws Exception
	{
	     Date date = null;
	     if(row != null)
	    {
	         IsFinishEnum isend = (IsFinishEnum)row.getCell("isEnd").getValue();
	         if(isend.equals(IsFinishEnum.FINISH))
	             date = FDCCommonServerHelper.getServerTime();
	         if(row.getCell("startTime").getValue() == null)
	        {
	             String getThemeId = (String)row.getCell("sellPlanID").getValue();
	             MarketPlanEntrySellPlanEntryInfo sellPlanInfo = MarketPlanEntrySellPlanEntryFactory.getRemoteInstance().getMarketPlanEntrySellPlanEntryInfo(new ObjectUuidPK(getThemeId));
	             if(sellPlanInfo != null)
	                 row.getCell("startTime").setValue(sellPlanInfo.getStartTime());
	        }
	         if(row.getCell("endTime").getValue() == null)
	             row.getCell("endTime").setValue(date);
	    }
	     setHeadTime();
	}
	
	protected void setHeadTime()
	    throws BOSException
	{
	     Date startDate = FDCCommonServerHelper.getServerTime();
	     Date endDate = FDCCommonServerHelper.getServerTime();
	     for(int i = 0; i < kdtEntry.getRowCount(); i++)
	    {
	         IRow row = kdtEntry.getRow(i);
	         if(row.getCell("startTime").getValue() != null && ((Date)row.getCell("startTime").getValue()).before(startDate))
	             startDate = (Date)row.getCell("startTime").getValue();
	         if(row.getCell("endTime").getValue() != null && ((Date)row.getCell("endTime").getValue()).after(endDate))
	             endDate = (Date)row.getCell("endTime").getValue();
	    }
	
	     pkStartDate.setValue(startDate);
	     pkEndDate.setValue(endDate);
	}
	
	protected void kdtEntry_editStopped(KDTEditEvent e)
	    throws Exception
	{
	     int rowIndex = e.getRowIndex();
	     String keyName = kdtEntry.getColumnKey(e.getColIndex());
	     if("isEnd".equals(keyName))
	    {
	         if(IsFinishEnum.FINISH.equals(kdtEntry.getRow(rowIndex).getCell(keyName).getValue()))
	        {
	             kdtEntry.getRow(rowIndex).getCell("startTime").getStyleAttributes().setBackground(FDCClientHelper.KDTABLE_COMMON_BG_COLOR);
	             kdtEntry.getRow(rowIndex).getCell("endTime").getStyleAttributes().setBackground(FDCClientHelper.KDTABLE_COMMON_BG_COLOR);
	             kdtEntry.getRow(rowIndex).getCell("factAmount").getStyleAttributes().setBackground(FDCClientHelper.KDTABLE_COMMON_BG_COLOR);
	        } else
	        {
	             kdtEntry.getRow(rowIndex).getCell("startTime").getStyleAttributes().setBackground(java.awt.Color.WHITE);
	             kdtEntry.getRow(rowIndex).getCell("endTime").getStyleAttributes().setBackground(java.awt.Color.WHITE);
	             kdtEntry.getRow(rowIndex).getCell("factAmount").getStyleAttributes().setBackground(java.awt.Color.WHITE);
	        }
	         setEndTime(kdtEntry.getRow(rowIndex));
	    } else
	     if("factAmount".equals(keyName))
	    {
	         BigDecimal factAmount = calculate("factAmount");
	         txtTotalFactAmount.setValue(factAmount);
	    } else
	     if("payAmount".equals(keyName))
	    {
	         BigDecimal payAmount = calculate("payAmount");
	         txtTotalPayAmount.setValue(payAmount);
	    } else
	     if("contractAmount".equals(keyName))
	    {
	         BigDecimal contractAmount = calculate("contractAmount");
	         txtTotalContractAmount.setValue(contractAmount);
	    } else
	     if("contractNumber".equals(keyName))
	    {
	         Object value = kdtEntry.getRow(rowIndex).getCell("contractNumber").getValue();
	         if(value != null)
	        {
	             if(value instanceof ContractBillInfo)
	            {
	                 kdtEntry.getRow(rowIndex).getCell("contractNumber").setValue((ContractBillInfo)value);
	                 kdtEntry.getRow(rowIndex).getCell("contractName").setValue(((ContractBillInfo)value).getName());
	                 kdtEntry.getRow(rowIndex).getCell("contractAmount").setValue(((ContractBillInfo)value).getAmount());
	                 kdtEntry.getRow(rowIndex).getCell("payAmount").setValue(getPayAmount(((ContractBillInfo)value).getId().toString()));
	                 ((MarketSchemeEntryInfo)kdtEntry.getRow(rowIndex).getUserObject()).setContractNumberID(((ContractBillInfo)value).getId());
	            } else
	            {
	                 kdtEntry.getRow(rowIndex).getCell("contractNumber").setValue((ContractWithoutTextInfo)value);
	                 kdtEntry.getRow(rowIndex).getCell("contractName").setValue(((ContractWithoutTextInfo)value).getName());
	                 kdtEntry.getRow(rowIndex).getCell("contractAmount").setValue(((ContractWithoutTextInfo)value).getAmount());
	                 kdtEntry.getRow(rowIndex).getCell("payAmount").setValue(getPayAmount(((ContractWithoutTextInfo)value).getId().toString()));
	                 ((MarketSchemeEntryInfo)kdtEntry.getRow(rowIndex).getUserObject()).setContractNumberID(((ContractWithoutTextInfo)value).getId());
	            }
	        } else
	        {
	             kdtEntry.getRow(rowIndex).getCell("contractName").setValue(null);
	             kdtEntry.getRow(rowIndex).getCell("contractAmount").setValue(FDCHelper.ZERO);
	             kdtEntry.getRow(rowIndex).getCell("payAmount").setValue(FDCHelper.ZERO);
	             ((MarketSchemeEntryInfo)kdtEntry.getRow(rowIndex).getUserObject()).setContractNumberID(null);
	        }
	         BigDecimal contractAmount = calculate("contractAmount");
	         txtTotalContractAmount.setValue(contractAmount);
	         BigDecimal payAmount = calculate("payAmount");
	         txtTotalPayAmount.setValue(payAmount);
	    } else
	     if("startTime".equals(keyName))
	    {
	         Date startDate = (Date)kdtEntry.getRow(rowIndex).getCell("startTime").getValue();
	         Date endDate = (Date)kdtEntry.getRow(rowIndex).getCell("endTime").getValue();
	         if(startDate != null && endDate != null && startDate.compareTo(endDate) > 0)
	        {
	             kdtEntry.getRow(rowIndex).getCell("startTime").setValue(null);
	             FDCMsgBox.showWarning(this, "\u5B9E\u9645\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u5C0F\u4E8E\u5B9E\u9645\u5F00\u59CB\u65E5\u671F\uFF01");
	             SysUtil.abort();
	        }
	         setHeadTime();
	    } else
	     if("endTime".equals(keyName))
	    {
	         Date startDate = (Date)kdtEntry.getRow(rowIndex).getCell("startTime").getValue();
	         Date endDate = (Date)kdtEntry.getRow(rowIndex).getCell("endTime").getValue();
	         if(startDate != null && endDate != null && startDate.compareTo(endDate) > 0)
	        {
	             kdtEntry.getRow(rowIndex).getCell("endTime").setValue(null);
	             FDCMsgBox.showWarning(this, "\u5B9E\u9645\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u5C0F\u4E8E\u5B9E\u9645\u5F00\u59CB\u65E5\u671F\uFF01");
	             SysUtil.abort();
	        }
	         setHeadTime();
	    }
	}
	
	private BigDecimal getPayAmount(String id)
	    throws BOSException
	{
	     BigDecimal amount = FDCHelper.ZERO;
	     IPaymentBill ipb = PaymentBillFactory.getRemoteInstance();
	     EntityViewInfo evi = new EntityViewInfo();
	     FilterInfo filter = new FilterInfo();
	     filter.getFilterItems().add(new FilterItemInfo("contractBillId", id));
	     evi.setFilter(filter);
	     evi.getSelector().add(new SelectorItemInfo("actPayLocAmt"));
	     PaymentBillCollection pbc = ipb.getPaymentBillCollection(evi);
	     if(pbc != null && pbc.size() != 0)
	    {
	         for(int i = 0; i < pbc.size(); i++)
	             amount = amount.add(pbc.get(i).getActPayLocAmt());
	
	    }
	     return amount;
	}
	
	private BigDecimal calculate(String name)
	{
	     BigDecimal amount = new BigDecimal(0);
	     for(int i = 0; i < kdtEntry.getRowCount(); i++)
	         if(kdtEntry.getRow(i).getCell(name).getValue() != null)
	             amount = amount.add((BigDecimal)kdtEntry.getRow(i).getCell(name).getValue());
	
	     return amount;
	}
	
	protected IObjectValue createNewData()
	{
	     MarketSchemeInfo info = new MarketSchemeInfo();
	     String enterprisePlanEntryId = (String)getUIContext().get("enterprisePlanEntryId");
	     if(enterprisePlanEntryId != null)
	    {
	         try
	        {
	             SelectorItemCollection sel = new SelectorItemCollection();
	             sel.add("*");
	             sel.add("sellPlanEntry.id");
	             sel.add("sellPlanEntry.esEntryId");
	             sel.add("parent.CU.*");
	             sel.add("parent.sellProject.*");
	             sel.add("parent.*");
	             MarketPlanEntryInfo entry = MarketPlanEntryFactory.getRemoteInstance().getMarketPlanEntryInfo(new ObjectUuidPK(enterprisePlanEntryId), sel);
	             MarketPlanEntrySellPlanEntryCollection col = entry.getSellPlanEntry();
	             for(int i = 0; i < col.size(); i++)
	            {
	                 MarketPlanEntrySellPlanEntryInfo sellPlan = col.get(i);
	                 String eseId = sellPlan.getId().toString();
	                 EntityViewInfo scEnv = new EntityViewInfo();
	                 FilterInfo scFilter = new FilterInfo();
	                 scFilter.getFilterItems().add(new FilterItemInfo("sellPlanID", eseId));
	                 scEnv.setFilter(scFilter);
	                 MarketSchemeEntryCollection enCol = MarketSchemeEntryFactory.getRemoteInstance().getMarketSchemeEntryCollection(scEnv);
	                 if(enCol.size() > 0)
	                {
	                     info = MarketSchemeFactory.getRemoteInstance().getMarketSchemeInfo(new ObjectUuidPK(enCol.get(0).getParent().getId()), getSelectors());
	                     if(info.getState().equals(FDCBillStateEnum.AUDITTED))
	                    {
	                         FDCMsgBox.showWarning(this, "\u5173\u8054\u4F01\u5212\u5B9E\u65BD\u5DF2\u5BA1\u6279\uFF01");
	                         SysUtil.abort();
	                    }
	                }
	                 boolean isAdd = true;
	                 for(int j = 0; j < info.getEntry().size(); j++)
	                     if(eseId.equals(info.getEntry().get(j).getSellPlanID()))
	                         isAdd = false;
	
	                 if(isAdd)
	                     if(sellPlan.getEsEntryId() == null)
	                    {
	                         MarketSchemeEntryInfo entryInfo = new MarketSchemeEntryInfo();
	                         entryInfo.setSellPlanID(eseId);
	                         entryInfo.setIsEnd(IsFinishEnum.UNSTART);
	                         info.getEntry().add(entryInfo);
	                    } else
	                    {
	                         MarketSchemeEntryInfo entryInfo = MarketSchemeEntryFactory.getRemoteInstance().getMarketSchemeEntryInfo(new ObjectUuidPK(sellPlan.getEsEntryId()));
	                         entryInfo.setSellPlanID(eseId);
	                         entryInfo.setId(null);
	                         info.getEntry().add(entryInfo);
	                    }
	            }
	
	             info.setSellProject(entry.getParent().getSellProject());
	             info.setEnterprisePlan(entry.getParent());
	             info.setOrgUnit(SysContext.getSysContext().getCurrentOrgUnit().castToFullOrgUnitInfo());
	             info.setThemeName(entry.getTheme());
	             info.setThemeDescription(entry.getDescribe());
	        }
	         catch(Exception e)
	        {
	             e.printStackTrace();
	             SysUtil.abort();
	        }
	         if(info.getId() == null)
	             info.setState(FDCBillStateEnum.SAVED);
	         else
	             setOprtState("EDIT");
	    }
	     info.setCU(SysContext.getSysContext().getCurrentCtrlUnit());
	     return info;
	}
	
	public SelectorItemCollection getSelectors()
	{
	     SelectorItemCollection sel = super.getSelectors();
	     sel.add("CU.*");
	     sel.add("entry.contractNumberID");
	     return sel;
	}
	
	protected void verifyInputForSave()
	    throws Exception
	{
	     if(getNumberCtrl().isEnabled())
	         VerifyInputUtil.verifyNull(this, txtNumber, "\u4F01\u5212\u5B9E\u65BD\u7F16\u53F7");
	}
	
	public void verifyInputForSubmint()
	    throws Exception
	{
	     verifyInputForSave();
	     VerifyInputUtil.verifyNull(this, pkStartDate, "\u5F00\u59CB\u65E5\u671F");
	     VerifyInputUtil.verifyNull(this, pkEndDate, "\u7ED3\u675F\u65E5\u671F");
	     Date startDate = (Date)pkStartDate.getValue();
	     Date endDate = (Date)pkEndDate.getValue();
	     if(startDate != null && endDate != null && startDate.compareTo(endDate) > 0)
	    {
	         FDCMsgBox.showWarning(this, "\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u5C0F\u4E8E\u5F00\u59CB\u65E5\u671F\uFF01");
	         SysUtil.abort();
	    }
	     for(int i = 0; i < kdtEntry.getRowCount(); i++)
	    {
	         IRow row = kdtEntry.getRow(i);
	         if(IsFinishEnum.FINISH.equals(row.getCell("isEnd").getValue()))
	        {
	             BigDecimal amount = (BigDecimal)row.getCell("factAmount").getValue();
	             if(amount == null)
	            {
	                 FDCMsgBox.showWarning(this, "\u5B9E\u9645\u91D1\u989D\u4E0D\u80FD\u4E3A\u7A7A\uFF01");
	                 kdtEntry.getEditManager().editCellAt(row.getRowIndex(), kdtEntry.getColumnIndex("factAmount"));
	                 SysUtil.abort();
	            }
	             if(amount.compareTo(FDCHelper.ZERO) == 0)
	            {
	                 FDCMsgBox.showWarning(this, "\u5B9E\u9645\u91D1\u989D\u4E0D\u80FD\u4E3A0\uFF01");
	                 kdtEntry.getEditManager().editCellAt(row.getRowIndex(), kdtEntry.getColumnIndex("factAmount"));
	                 SysUtil.abort();
	            }
	             if(row.getCell("startTime").getValue() == null)
	            {
	                 FDCMsgBox.showWarning(this, "\u5B9E\u9645\u5F00\u59CB\u65E5\u671F\u4E0D\u80FD\u4E3A\u7A7A\uFF01");
	                 kdtEntry.getEditManager().editCellAt(row.getRowIndex(), kdtEntry.getColumnIndex("startTime"));
	                 SysUtil.abort();
	            }
	             if(row.getCell("endTime").getValue() == null)
	            {
	                 FDCMsgBox.showWarning(this, "\u5B9E\u9645\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u4E3A\u7A7A\uFF01");
	                 kdtEntry.getEditManager().editCellAt(row.getRowIndex(), kdtEntry.getColumnIndex("endTime"));
	                 SysUtil.abort();
	            }
	        }
	    }
	
	}
	
	protected void kdtEntry_tableClicked(KDTMouseEvent e)
	    throws Exception
	{
	     super.kdtEntry_tableClicked(e);
	     if(e.getColIndex() == kdtEntry.getColumnIndex("contentItem"))
	         showDialog(this, kdtEntry, 250, 100, 500, getOprtState());
	}
	
	public void showDialog(JComponent owner, KDTable table, int X, int Y, int len, String state)
	{
	     int rowIndex = table.getSelectManager().getActiveRowIndex();
	     int colIndex = table.getSelectManager().getActiveColumnIndex();
	     ICell cell = table.getCell(rowIndex, colIndex);
	     BasicView view = table.getViewManager().getView(5);
	     java.awt.Point p = view.getLocationOnScreen();
	     java.awt.Rectangle rect = view.getCellRectangle(rowIndex, colIndex);
	     java.awt.Window parent = SwingUtilities.getWindowAncestor(owner);
	    KDDetailedAreaDialog dialog;
	     if(parent instanceof java.awt.Dialog)
	         dialog = new KDDetailedAreaDialog((java.awt.Dialog)parent, X, Y, true);
	     else
	     if(parent instanceof java.awt.Frame)
	         dialog = new KDDetailedAreaDialog((java.awt.Frame)parent, X, Y, true);
	     else
	         dialog = new KDDetailedAreaDialog(true);
	     String vals = cell.getValue().toString();
	     dialog.setData(vals);
	     dialog.setPRENTE_X(p.x + rect.x + rect.width);
	     dialog.setPRENTE_Y(p.y + rect.y);
	     dialog.setMaxLength(len);
	     dialog.setEditable(false);
	     dialog.show();
	}
	
	public static void setWrapFalse(ICell cell)
	{
	     if(cell != null)
	         cell.getStyleAttributes().setWrapText(true);
	}
	
	protected void setThisCellEditor(KDTable table, String colName, boolean isRequired, int maxLength)
	{
	     KDDetailedArea area = new KDDetailedArea(280, 250);
	     area.setRequired(isRequired);
	     area.setEnabled(true);
	     area.setMaxLength(maxLength);
	     table.getColumn(colName).setEditor(new KDTDefaultCellEditor(area));
	}
    /**
     * output getBizInterface method
     */
    protected com.kingdee.eas.framework.ICoreBase getBizInterface() throws Exception
    {
        return com.kingdee.eas.crm.market.MarketSchemeFactory.getRemoteInstance();
    }

    /**
     * output createNewDetailData method
     */
    protected IObjectValue createNewDetailData(KDTable table)
    {
		
        return new com.kingdee.eas.crm.market.MarketSchemeEntryInfo();
    }

	protected void attachListeners() {
		
	}
	protected void detachListeners() {
		
	}
	protected KDTextField getNumberCtrl() {
		return txtNumber;
	}

}